/**
 * @param e 图片对象
 */
function showBigImage(e) {
    layer.open({
        type: 1,
        title: false,
        closeBtn: 0,
        shadeClose: true, //点击阴影关闭
        area: [$(e).width + 'px', $(e).height + 'px'], //宽高
        content: "<img src=" + $(e).attr('src') + " />"
    });
}

/**
 * 编辑 用户详情详情对话框
 */
var UserInfoInfoDlg = {
    data: {
		userInfoId: "",
		openId: "",
		userInfoName: "",
		headUrl: "",
		wxType: "",
		createTime: ""
    }
};

layui.use(['layer', 'form', 'admin', 'ax'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var layer = layui.layer;

    // 让当前iframe弹层高度适应
    admin.iframeAuto();

    // 点击userInfoName时 弹出树，不需要请删掉
    $('#userInfoName').click(function () {
        var formName = encodeURIComponent("parent.UserInfoInfoDlg.data.userInfoName");
        var formId = encodeURIComponent("parent.UserInfoInfoDlg.data.userInfoId");
        var treeUrl = encodeURIComponent("/userInfo/userInfoTreeList");

        layer.open({
            type: 2,
            title: '父级 用户详情选择',
            area: ['300px', '200px'],
            content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,
            end: function () {
                $("#userInfoId").val(UserInfoInfoDlg.data.userInfoId);
                $("#userInfoName").val(UserInfoInfoDlg.data.userInfoName);
            }
        });
    });
	
	//获取详情信息，填充表单
    var ajax = new $ax(Feng.ctxPath + "/userInfo/detail?userInfoId=" + Feng.getUrlParam("userInfoId"));
    var result = ajax.start();
    form.val('userInfoForm', result.data);
    $("#headUrl").attr("src",result.data.headUrl);

    // 表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var ajax = new $ax(Feng.ctxPath + "/userInfo/edit", function (data) {
            Feng.success("添加成功！");
            //返回
			window.location.href = Feng.ctxPath + "/userInfo?userInfoId=" + $("#userInfoId").val();
            /** 窗口返回前页模式
            //传给上个页面，刷新table用
            //admin.putTempData('formOk', true);

            //关掉对话框
            admin.closeThisDialog();
            */
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();
		return false;//返回
    });
	
	//返回按钮，需要同步修改页面按钮id
    $("#backupPage").click(function () {
        var wxTypeTo = $("#wxTypeTo").val();
        var v = $("#userInfoId").val();
        if(wxTypeTo !=null){
            window.location.href = Feng.ctxPath + "/userInfo/onco?userInfoId=" + $("#userInfoId").val();
        }else{
            window.location.href = Feng.ctxPath + "/userInfo?userInfoId=" + $("#userInfoId").val();
        }
    });
});